package org.amuthu.expression.terminal;

import org.amuthu.parser.ExpressionVisitor;

/**
 * Class that represents a quote kind, e.g. day open, day close, etc.
 * Originally there was a separate class for each quote kind but
 * this was deemed a little excessive, so it was all folded into
 * a single class.
 */
public class QuoteExpression extends TerminalExpression
{

   // Quote kind - Quote.DAY_OPEN, Quote.DAY_CLOSE, Quote.DAY_LOW, etc...
   private QuoteExprType quoteKind;

   /**
    * Create a new quote expression.
    *
    * @param quoteKind Kind of quote. One of {@link Quote#DAY_OPEN},
    *        {@link Quote#DAY_CLOSE}, {@link Quote#DAY_LOW},
    *        {@link Quote#DAY_HIGH} or {@link Quote#DAY_VOLUME}
    */
   public QuoteExpression(QuoteExprType quoteKind)
   {
      assert (quoteKind == QuoteExprType.DAY_OPEN || quoteKind == QuoteExprType.DAY_CLOSE
              || quoteKind == QuoteExprType.DAY_LOW || quoteKind == QuoteExprType.DAY_HIGH
              || quoteKind == QuoteExprType.DAY_VOLUME);
      this.quoteKind = quoteKind;
   }

   /**
    * Get the quote kind.
    *
    * @return	the quote kind, one of: {@link Quote#DAY_OPEN},
    * {@link Quote#DAY_CLOSE}, {@link Quote#DAY_HIGH}, {@link Quote#DAY_LOW}
    * or {@link Quote#DAY_VOLUME}.
    */
   public QuoteExprType getQuoteKind()
   {
      return quoteKind;
   }

   /**
    * Get the type of the expression.
    *
    * @return {@link #FLOAT_QUOTE_TYPE} or {@link #INTEGER_QUOTE_TYPE}.
    */
   @Override
   public int getType()
   {
      if (getQuoteKind() == QuoteExprType.DAY_VOLUME)
      {
         return INTEGER_QUOTE_TYPE;
      }
      else
      {
         return FLOAT_QUOTE_TYPE;
      }
   }

   @Override
   public String toString()
   {
      switch (quoteKind)
      {
         case DAY_OPEN:
            return "open";
         case DAY_CLOSE:
            return "close";
         case DAY_HIGH:
            return "high";
         case DAY_LOW:
            return "low";
         default:
            assert quoteKind == QuoteExprType.DAY_VOLUME;
            return " volume ";
      }
   }

   @Override
   public void accept(ExpressionVisitor visitor)
   {
      visitor.visit(this);
   }
}
